import pymysql
import os
import celery

from django.conf import settings
from celery.schedules import crontab


pymysql.install_as_MySQLdb()

# project_name = 'travel_guide'
# project_settings = '%s.settings' % project_name

# 注册环境变量
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'travel_guide.settings')

# 注册APP
app = celery.Celery('travel_guide',
                    broker='amqp://luohao:123456@120.77.222.217:5672/vhost1')

# 从默认配置 文件读取配置信息
app.config_from_object('django.conf:settings')

# Celery加载所有注册的应用列表
app.autodiscover_tasks(['common'])

app.conf.update(
    timezone=settings.TIME_ZONE,
    enable_utc=True,
    beat_schedule={
        'task1': {
            'task': 'crontab_things',
            'schedule': crontab(),
            'args': ('你妈妈喊你回家吃饭了！',)
        },
    }
)


@app.task()
def crontab_things(msg):
    print(msg)
